import 'package:flutter_model_package/parse_base.dart';
import 'package:parse_server_sdk/parse_server_sdk.dart';

import 'Branch.dart';

class BranchLayer extends MSParseBase {
  BranchLayer() : super("BranchLayer");

  BranchLayer.cloe() : this();
////
  @override
  BranchLayer clone(Map<String, dynamic> map) =>
      BranchLayer.cloe()
        ..fromJson(map);

  QueryBuilder<BranchLayer> tree() {
    return QueryBuilder(BranchLayer())
      ..whereEqualTo("path", this);
  }

  static QueryBuilder<BranchLayer> forExternal() {
    return QueryBuilder(BranchLayer())
      ..whereEqualTo("code", "external");
  }

  QueryBuilder<BranchLayer> getAllBranchLayer() {
    return QueryBuilder(this)
      ..whereMatchesQuery("parent", BranchLayer.forExternal())
      ..includeObject(["branches", "branches.contacts"]);
  }
  Iterable<Branch> get branchs =>get<List<dynamic>>("branches").map((e) => e);

  QueryBuilder<BranchLayer> searchBranch() {
    return QueryBuilder(this)
      ..whereMatchesQuery("parent", BranchLayer.forExternal());
  }
}
